package com.wg.msshopsp.backendmanagement.user.service;

import com.wg.msshopsp.backendmanagement.user.entity.User;
import com.wg.msshopsp.backendmanagement.user.mapper.UserMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wg.msshopsp.entity.QueryPageDto;
import com.wg.msshopsp.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService extends ServiceImpl<UserMapper, User> {
    @Autowired
    private UserMapper userMapper;

    public Page<User> queryUsers(User user, QueryPageDto pager) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtil.isNotEmpty(user.getNc()), "nc", user.getNc())
                .like(StringUtil.isNotEmpty(user.getPhone()), "phone", user.getPhone())
                .like(user.getStatus() != null && StringUtil.isNotEmpty(String.valueOf(user.getStatus())), "status", user.getStatus())
                .eq(user.getShopCount() != null, "shop_count", user.getShopCount());

        // 执行分页查询
        Page<User> pageInfo = userMapper.selectPage(
                new Page<>(pager.getPageNum(), pager.getPageSize()),
                queryWrapper
        );
        return pageInfo;
    }
}
